@extends('admin/layouts/admin')
@section('title', '内容列表')
@section('main')
<div class="main-title"><h2>内容管理</h2></div>
<div class="main-section form-inline">
  <a href="{{ url('content/add') }}" class="btn btn-success">+ 新增</a>
  <select class="j-select form-control" style="min-width:120px;margin-left:8px">
    <option value="{{ url('content', ['cid' => 0]) }}">所有栏目</option>
    @foreach ($category as $v)
    <option value="{{ url('content', ['id' => $v['id']]) }}" @if ($cid == $v['id']) selected @endif>
      @if ($v['level']) --- @endif {{ $v['name'] }}
    </option>
    @endforeach
  </select>
</div>
<div class="main-section">
  <table class="table table-striped table-bordered table-hover">
    <thead>
      <tr>
        <th width="75">序号</th><th>栏目</th><th>图片</th><th>标题</th><th>状态</th><th>创建时间</th><th width="100">操作</th>
      </tr>
    </thead>
    <tbody>
      <!-- 内容列表 -->
      @if (empty($content))
      <tr><td colspan="3" class="text-center">还没有添加内容</td></tr>
      @endif
      @foreach ($content as $v)
      <tr>
        <td>{{ $v->id }}</td>
        <td>@if(isset($v->category)) 
              {{ $v->category->name }}
            @else
              未知分类
            @endif
        </td>
        <td><img @if ($v->image) src="/static/upload/{{ $v->image }}" @else src="{{ asset('admin') }}/img/noimg.png" @endif width="50" height="50" alt=""></td>
        <td>{{ $v->title }}</td>
        <td>@if ($v->status == 1) 默认 @else 推荐 @endif</td>
        <td>{{ $v->created_at }}</td>
        <td>
          <a href="{{ url('content/edit', ['id' => $v['id']]) }}" style="margin-right:5px">编辑</a>
          <a href="{{ url('content/delete', ['id' => $v['id']]) }}" class="j-del text-danger">删除</a>
        </td>
      </tr>
      @endforeach
    </tbody>
  </table>
</div>
<script>
  main.menuActive('content');
  $('.j-select').change(function () {
    location.href = $(this).val();
  });
  $('.j-del').click(function () {
    if (confirm('您确定要删除此项？')) {
      var data = { _token: '{{ csrf_token() }}' };
      main.ajaxPost({ url: $(this).attr('href'), data: data}, function () {
        location.reload();
      });
    }
    return false;
  });
</script>
@endsection